<?php
require_once("page.class.php");
require_once("db_functions.php");


class preporuke extends page{
	
	var $db;
	
	var $adminUsers = array(
		2,	// JOVANOVIC VOISLAV
		9,	// ZARKO POPOVIC
		8,	// JASMINA RADOSAVLJEVIC
		4	// DUBRAVKA FILIPOVIC
	);
	
	var $nonactiveStyle="nonactive";
	
	function preporuke($get){
		$this->loadConfig();
		if(!$this->isUserLoggedIn()){
			header("Location: index.php");
		}
		
		$action = $get["a"];
		$this->db = new db_functions();
		
		$usergroup = $this->getUserLevel();
		$userid = $_COOKIE["ypu"];
		$s = array_search($userid,$this->adminUsers);
		$isadminuser = ($s !== false)?true:false;
		$isadmingroup = intval($usergroup["rights"]["preporuke"]) >0;
		if(!$isadmingroup && !$isadminuser){
			$this->assign("admin_comment_start","<!--");
			$this->assign("admin_comment_end","-->");
		}
		
		switch ($action){
			case "getKomitentPreporuke":
				$this->getKomitentPreporuke($get["id"]);
				break;
			case "updateKomdels":
				$this->updateKomdels();
				break;
			case "save":
				$this->prepSave($get);
				break;
			case "saveComm":
				$this->commSave();
				break;
			case "delComm":
				$commID = getFromInput("id");
				$q = "DELETE FROM komentari WHERE komentar_id=$commID";
				if($this->db->alterTable($q)){
					echo "Komentar uspešno obrisan.";
					$log = new log_change();
					$log->user = $_COOKIE["ypu"];
					$log->time = time();
					$log->ip = $_SERVER['REMOTE_ADDR'];
					$log->table = "komentari";
					$log->attr 	= "komentar_id";
					$log->state = 3;
					$log->value = $commID;
					$log->write();
				}else{
					echo mysql_error();
				}
				break;
			case "delPrep":
				$prepid=getFromInput("id");
				$ok=true;
				$q = "DELETE FROM preporuke WHERE preporuka_id=$prepid; ";
				if(!$this->db->alterTable($q)){
					$ok=false;
				}
				$q = "DELETE FROM komentari WHERE preporuka_id=$prepid";
				if(!$this->db->alterTable($q)){
					$ok=false;
				}
				
				if($ok){
					echo "Preporuka i njeni komentari su izbrisani.";
					$log = new log_change();
					$log->user = $_COOKIE["ypu"];
					$log->time = time();
					$log->ip = $_SERVER['REMOTE_ADDR'];
					$log->table = "preporuke";
					$log->attr 	= "preporuka_id";
					$log->state = 3;
					$log->value = $prepid;
					$log->write();
				}else{
					echo mysql_error();
				}
				
				break;
			default:
				$this->prepAdmin();
		}
	}
	
	function prepAdmin(){
		$kom_cnt="0";
		
		$delid		= trim(getFromInput("delatnost"));
		$komitent	= trim(getFromInput("komitent"));
		$tip_prep	= trim(getFromInput("tip_preporuke"));
		$tema_prep	= trim(getFromInput("tema_preporuke"));
		$active		= trim(getFromInput("kontrola"));
		$komentar	= trim(getFromInput("komentar"));
		$komentar = strlen($komentar)==0?"-1":$komentar;
		
		$this->assign("filter_komitent",$komitent);
		$this->assign("kontrola_id",array("0","1"));
		$this->assign("kontrola_name",array("ne","da"));
		$this->assign("komentar_id",array("0","1"));
		$this->assign("komentar_name",array("ne","da"));
		
		$arrsel = array("","");
		if(strlen($active)>0){
			if($active>=0){
				if($active>0){
					$arrsel = array(""," selected");
				}else{
					$arrsel = array(" selected","");
				}
			}
		}
		$arrsel1 = array("","");
		if(strlen($komentar)>0){
			if($komentar>=0){
				if($komentar>0){
					$arrsel1 = array(""," selected");
				}else{
					$arrsel1 = array(" selected","");
				}
			}
		}
		
		$this->assign("kontrola_selected",$arrsel);
		$this->assign("komentar_selected",$arrsel1);
		$delid = $delid>0?$delid:null;
		$polja = $this->get_Delatnosti(null,$delid);
			$this->assign("delatnost_id",$polja["polje_id"]);
			$this->assign("delatnost_ime",$polja["polje_ime"]);
			$this->assign("delatnost_selected",$polja["polje_selected"]);
			$this->assign("delatnost_display",$polja["polje_display"]);
		
		$polja = $this->get_PreporukeTipovi($tip_prep);
			$this->assign("filter_tip_id",$polja["polje_id"]);
			$this->assign("filter_tip_name",$polja["polje_ime"]);
			$this->assign("filter_tip_selected",$polja["polje_selected"]);
		
		$polja = $this->get_PreporukeTeme($tema_prep);
			$this->assign("filter_tema_id",$polja["polje_id"]);
			$this->assign("filter_tema_name",$polja["polje_ime"]);
			$this->assign("filter_tema_selected",$polja["polje_selected"]);
		
		$polja = $this->get_PreporukeTeme($tema_prep);
			$this->assign("filter_tema_id",$polja["polje_id"]);
			$this->assign("filter_tema_name",$polja["polje_ime"]);
			$this->assign("filter_tema_selected",$polja["polje_selected"]);
			
		if(strlen($komitent)>0 || $delid>0 || $tip_prep>0 || $tema_prep>0 || (strlen($active)>0 && $active>=0) || (strlen($komentar)>0 && $komentar>=0)){
			list($style_li,$style_h1,$style_date,$style_sign,$style_comm) = $this->getStyle();
			
			$q = "SELECT p.*, k.komitent_name "
				."FROM preporuke p, komitenti k "
				."WHERE p.kom_id=k.komitent_id ";
			
			if($komitent){
				if(preg_match('/^\d+$/',$komitent)){
					$q .= "AND k.komitent_id=$komitent ";
				}else{
					$q .= "AND ( (k.komitent_name LIKE '%$komitent%') OR (k.komitent_name1 LIKE '%$komitent%') ) ";
				}
			}
			
			if($delid>0){
				$q .= "AND p.del_id=$delid ";
			}
			if($tip_prep>0){
				$q .= "AND p.tip=$tip_prep ";
			}
			if($tema_prep>0){
				$q .= "AND p.tema=$tema_prep ";
			}
			
			$uslov = strlen($active) && $active>=0;
			if($uslov){
				$q .= "AND p.kontrola=$active ";
			}
			
			$q .= "ORDER BY komitent_name, p.datum DESC";
			
			$res = $this->db->select2($q);
			if($res !== false){
				foreach ($res as $k=>$row){
					
					$kd = $this->get_KomitentDelatnosti($row["kom_id"]);
					if($kd !== false){
						$komdels[] = implode(";",$kd);
					}else{
						$komdels[] = "nema ".$row["kom_id"];
					}
					
					$comments = $this->getPrepComments($row["preporuka_id"]);
					if($komentar>=0){
						if($komentar>0 && $comments["count"]<1){
							continue;
						}elseif($komentar<1 && $comments["count"]>0){
							continue;
						}
					}
					
					$search = @array_search($row["kom_id"],$kom_ids);
					if($k==0 || $search === false){
						$kom_ids[] = $row["kom_id"];
						$kom_names[] = $row["komitent_name"];
						$kom_num[] = 1;
					}else{
						$kom_num[$search] ++;
					}
					
					$prep_comms[]	= $comments["txt"];
					$prep_comms_cnt[]= $comments["count"]>0?$comments["count"]:"0";
					
					
					/*$row["text"] = str_replace("<br />","\n",$row["text"]);
					$row["text"] = str_replace("<br/>","\n",$row["text"]);
					$row["text"] = str_replace("<br>","\n",$row["text"]);*/
					$row["text"] = str_replace("\n","<br />",$row["text"]);
					
					$prep_ids[]			= $row["preporuka_id"];
					$prep_kom_ids[]		= $row["kom_id"];
					$prep_kom_names[]	= $row["komitent_name"];
					$prep_del_ids[]		= $row["del_id"];
					$prep_titles[]		= strlen(trim($row["naslov"]))>0?$row["naslov"]:"&nbsp;";
					$prep_text[]		= $row["text"];
					$prep_control[]		= $row["kontrola"]==1?"":$this->nonactiveStyle;
					$prep_control1[]	= $row["kontrola"];
					$prep_tip[]			= $row["tip"];
					$prep_tip_name[]	= $this->db->getOne("SELECT tip_name FROM preporuke_tipovi WHERE tip_id=".$row["tip"]);
					$prep_tema[]		= strtolower($row["tema"]);
					$prep_tema_name[]	= $this->db->getOne("SELECT tema_name FROM preporuke_teme WHERE tema_id=".$row["tema"]);
					$prep_date[]		= @date($this->getFromConfig("long_date"),$row["datum"]);
					$prep_sign[]		= $row["posiljalac"];
					$prep_mesta[]		= $row["mesto"];
					$prep_adrese[]		= $row["adresa"];
					$prep_emails[]		= $row["email"];
					$prep_tels[]		= $row["telefon"];
					
					$style["li"][] = $style_li[strtolower($row["tip_name"])];
					$style["h1"][] = $style_h1[strtolower($row["tip_name"])];
					$style["date"][] = $style_date[strtolower($row["tip_name"])];
					$style["comm"][] = $style_comm[strtolower($row["tip_name"])];
					$style["sign"][] = $style_sign[strtolower($row["tip_name"])];
				}
				// komitent search list
				$this->assign("kom_id",$kom_ids);
				$this->assign("komdels",$komdels);
				$this->assign("kom_name",$kom_names);
				$this->assign("kom_num",$kom_num);
				$kom_cnt = count($kom_ids);
				
				// preporuke list
				$this->assign("prep_id",$prep_ids);
				$this->assign("prep_kom_id",$prep_kom_ids);
				$this->assign("prep_kom_name",$prep_kom_names);
				$this->assign("prep_del_id",$prep_del_ids);
				$this->assign("naslov",$prep_titles);
				$this->assign("text",$prep_text);
				$this->assign("kontrola",$prep_control);
				$this->assign("kontrola1",$prep_control1);
				$this->assign("tip",$prep_tip);
				$this->assign("tip_name",$prep_tip_name);
				$this->assign("tema_id",$prep_tema);
				$this->assign("tema",$prep_tema_name);
				$this->assign("datum",$prep_date);
				$this->assign("posiljalac",$prep_sign);
				$this->assign("mesto",$prep_mesta);
				$this->assign("adresa",$prep_adrese);
				$this->assign("email",$prep_emails);
				$this->assign("telefon",$prep_tels);
				$this->assign("prepComments",$prep_comms);
				$this->assign("comm_num",$prep_comms_cnt);
				
				// style
				//print_rarray($style);
				$this->assign("style_li",$style["li"]);
				$this->assign("style_h1",$style["h1"]);
				$this->assign("style_date",$style["date"]);
				$this->assign("style_comm",$style["comm"]);
				$this->assign("style_sign",$style["sign"]);
				
				$this->assign("preporuke",$this->parseTemplate("preporuke/preporuke.tpl"));
			}
		}
		$this->assign("edit_form",$this->parseTemplate("preporuke/edit_prep_form.tpl"));
		$this->assign("edit_comm_form",$this->parseTemplate("preporuke/edit_comm_form.tpl"));
		$this->assign("kom_count",$kom_cnt);
		echo $this->parseTemplate("preporuke/admin.tpl");
	}
	function updateKomdels(){
		$komid = getFromInput("id");
		$out = $this->get_KomitentDelatnosti($komid);
		echo @implode(";",$out);
	}
	function prepSave($params){
		foreach ($params as $k=>$v){
			$v = utf8RawUrlDecode($v);
			$$k = trim(utf8RawChrDecode($v));
		}
		
		$ok = true;
		
		$mailchk = preg_match('/'.$this->getFromConfig("email_regexp").'/',$edit_email);
		$phonechk = preg_match('/'.$this->getFromConfig("phone_regexp").'/',$edit_telefon);
		
		if(	$komitent_edit_id<1 ||
			$delatnost_edit<1 || 
			!strlen(trim($naslov_edit)) ||
			!strlen(trim($edit_ime)) ||
			!strlen(trim($edit_mesto)) ||
			!strlen(trim($edit_adresa)) ||
			!strlen(trim($text_edit)) ||
			$tip_edit<1 ||
			$tema_edit<1 ||
			!$mailchk ||
			!$phonechk
		  ){
			
				$ok = false;
		}
		
		
		if($ok){
			if($new){
				$q = "INSERT INTO "
					."preporuke(kom_id, del_id, naslov, posiljalac, mesto, adresa, text, datum, tip, tema, email, telefon, kontrola) "
					."VALUES ("
					."$komitent_edit_id,"
					."$delatnost_edit,"
					."'$naslov_edit',"
					."'$edit_ime',"
					."'$edit_mesto',"
					."'$edit_adresa',"
					."'".str_replace("\n","<br />",html_entity_decode(addslashes($text_edit)))."',"
					.time().","
					."'$tip_edit',"
					."'$tema_edit',"
					."'$edit_email',"
					."'$edit_telefon',"
					."'$kontrola'"
					.")";
			}else{
				$q = "UPDATE preporuke SET "
					."kom_id=$komitent_edit_id,"
					."del_id=$delatnost_edit,"
					."naslov='$naslov_edit',"
					."posiljalac='$edit_ime',"
					."mesto='$edit_mesto',"
					."adresa='$edit_adresa',"
					."text='".str_replace("\n","<br />",addslashes($text_edit))."',"
					."tip='$tip_edit',"
					."tema='$tema_edit',"
					."email='$edit_email',"
					."telefon='$edit_telefon',"
					."kontrola='$kontrola' "
					."WHERE preporuka_id=$prep_id_edit";
			}
			if($this->db->alterTable($q)){
				echo "$komitent_edit_id{!}";
				echo "Preporuka je sačuvana.";
				
				if($new){
					$prep_id_edit = $this->db->getOne("SELECT LAST_INSERT_ID() FROM preporuke");
				}
				
				$log = new log_change();
				$log->user = $_COOKIE["ypu"];
				$log->time = time();
				$log->ip = $_SERVER['REMOTE_ADDR'];
				$log->table = "preporuke";
				$log->attr 	= "preporuka_id";
				$log->state = $new==1?1:2;
				$log->value = $prep_id_edit;
				$log->write();
			}else{
				echo mysql_error();
			}
			
		}else{
			//echo "0{!}";
			echo "Greška!\nNiste popunili sva obavezna polja ili polja nisu validna.";
		}
	}
	
	function commSave(){
		foreach ($_POST as $k=>$v){
			$v = utf8RawUrlDecode(trim($v));
			$$k = trim(utf8RawChrDecode($v));
		}
		$kom_kontrola = $kom_kontrola>0?1:0;
		
		$ok = true;
		$mailchk = preg_match('/'.$this->getFromConfig("email_regexp").'/',$kom_edit_email);
		$phonechk = preg_match('/'.$this->getFromConfig("phone_regexp").'/',$kom_edit_tel);
		if(
			strlen($kom_edit_naslov)==0 ||
			strlen($kom_edit_text)==0 ||
			strlen($kom_edit_posiljalac)==0 ||
			strlen($kom_edit_mesto)==0 ||
			strlen($kom_edit_adresa)==0 ||
			!$mailchk ||
			!$phonechk
		){
			$ok = false;
		}
		
		if($ok){
			if($new){
				$q = "INSERT INTO "
					."komentari(preporuka_id, komentar, posiljalac, grad, adresa, datum, naslov, telefon, email, kontrola) "
					."VALUES ("
					."$edit_commprep_id,"
					."'".str_replace("\n","<br />",$kom_edit_text)."',"
					."'$kom_edit_posiljalac',"
					."'$kom_edit_mesto',"
					."'$kom_edit_adresa',"
					.time().", "
					."'$kom_edit_naslov',"
					."'$kom_edit_tel',"
					."'$kom_edit_email',"
					."$kom_kontrola"
					.")";
			}else{
				$q = "UPDATE komentari SET "
					."naslov='$kom_edit_naslov', "
					."komentar='".str_replace("\n","<br />",$kom_edit_text)."', "
					."posiljalac='$kom_edit_posiljalac', "
					."grad='$kom_edit_mesto', "
					."adresa='$kom_edit_adresa', "
					."email='$kom_edit_email', "
					."telefon='$kom_edit_tel', "
					."kontrola=$kom_kontrola "
					."WHERE komentar_id=$edit_comment_id";
			}
			//echo "$q\n\n$edit_komitent_id";die();
			if($this->db->alterTable($q)){
				echo "$edit_komitent_id{!}";
				echo "Komentar je sačuvan.";
				
				if($new){
					$commID = $this->db->getOne("SELECT LAST_INSERT_ID() FROM komentari");
				}else{
					$commID = $edit_comment_id;
				}
				
				$log = new log_change();
				$log->user = $_COOKIE["ypu"];
				$log->time = time();
				$log->ip = $_SERVER['REMOTE_ADDR'];
				$log->table = "komentari";
				$log->attr 	= "komentar_id";
				$log->state = $new==1?1:2;
				$log->value = $commID;
				$log->write();
			}else{
				echo mysql_error();
			}
		}else{
			if(!$mailchk){
				echo "E-mail nije validan";
			}else if(!$phonechk){
				echo "Broj telefona nije validan.";
			}else{
				echo "Niste popunili sva polja";
			}
		}
	}
	
	function getKomitentPreporuke($komid){
		$this->assign("admin_comment_start","<!--");
		$this->assign("admin_comment_end","-->");
		$q = "SELECT preporuke.*, tip_name, tema_name "
			."FROM preporuke, preporuke_tipovi, preporuke_teme "
			."WHERE preporuke_tipovi.tip_id=preporuke.tip "
			."AND preporuke_teme.tema_id=preporuke.tema "
			."AND kontrola=1 "
			."AND kom_id=$komid ORDER BY datum DESC";
		$res = $this->db->select2($q);
		if($res !== false){
			foreach ($res as $row){
				$comments = $this->db->select2("SELECT * FROM komentari WHERE preporuka_id=".$row["preporuka_id"]);
				$row["komentari"] = $comments;
				
				$data[$row["del_id"]][] = $row;
			}
			//print_rarray($data);
			
			list($style_li,$style_h1,$style_date,$style_sign,$style_comm) = $this->getStyle();
			
			$out = "";
			foreach ($data as $delid=>$d){
				$out .= $delid."{!}";
				$arr=array();
				foreach ($d as $p){
					foreach ($p as $k=>$v){
						switch ($k){
							case "kontrola":
								$arr[$k][] = ($v==0)?$this->nonactiveStyle:"";
								break;
							case "datum":
								$arr[$k][] = $v>0?date($this->getFromConfig("short_date"),$v):"";
								break;
							case "komentari":
								$arr[$k][] = $this->parseKomentari($v);
								break;
							default:
								$arr[$k][]=$v;
								break;
						}
					}
					$arr["comm_num"][] = is_array($p["komentari"])>0?count($p["komentari"]):"0";
					$arr["style_li"][] = $style_li[strtolower($p["tip_name"])];
					$arr["style_h1"][] = $style_h1[strtolower($p["tip_name"])];
					$arr["style_date"][] = $style_date[strtolower($p["tip_name"])];
					$arr["style_sign"][] = $style_sign[strtolower($p["tip_name"])];
					$arr["style_comm"][] = $style_comm[strtolower($p["tip_name"])];
				}
				
				$this->assign("tip_preporuke",$arr["tip_name"]);
				$this->assign("prep_id",$arr["preporuka_id"]);
				$this->assign("naslov",$arr["naslov"]);
				$this->assign("kontrola",$arr["kontrola"]);
				$this->assign("tema",$arr["tema_name"]);
				$this->assign("datum",$arr["datum"]);
				$this->assign("text",$arr["text"]);
				$this->assign("posiljalac",$arr["posiljalac"]);
				$this->assign("prepComments",$arr["komentari"]);
				
				// style assigning
				$this->assign("style_li",$arr["style_li"]);
				$this->assign("style_h1",$arr["style_h1"]);
				$this->assign("style_date",$arr["style_date"]);
				$this->assign("style_sign",$arr["style_sign"]);
				$this->assign("style_comm",$arr["style_comm"]);
				
				// KOMENTARI
				//print_rarray($arr["comm_num"]);
				$this->assign("comm_num",$arr["comm_num"]);
				
				$html = $this->parseTemplate("preporuke/preporuke.tpl");
				$out .= $html."{!!}";
			}
			echo substr($out,0,strlen($out)-4);
		}else{
			echo 0;
		}
	}
	function parseKomentari($comm){
		if(is_array($comm)){
			$ret ="";
			foreach ($comm as $k=>$v){
				foreach ($v as $m=>$n){
					switch ($m){
						case "datum":
							$a[$m][] = date($this->getFromConfig("short_date"),$n);
							break;
						default:
							$a[$m][] = $n;
							break;
					}
				}
			}
			$last = array_fill(0,count($comm),"");
			$last[count($last)-1] = "last";
			$this->assign("comm_id",$a["komentar_id"]);
			$this->assign("comm_datum",$a["datum"]);
			$this->assign("comm_naslov",$a["naslov"]);
			$this->assign("comm",$a["komentar"]);
			$this->assign("comm_sign",$a["posiljalac"]);
			$this->assign("comm_control",$a["kontrola"]);
			$this->assign("comm_last",$last);
			
			$ret = $this->parseTemplate("preporuke/komentari.tpl");
			return $ret;
		}else{
			return null;
		}
	}
	
	function getPrepComments($prepid){
		$ret = "";
		$q = "SELECT komentari.*, preporuke.kom_id FROM komentari, preporuke WHERE preporuke.preporuka_id=komentari.preporuka_id AND komentari.preporuka_id=$prepid ORDER BY datum DESC";
		$comm = $this->db->select2($q);
		
		if($comm !== false){
			foreach ($comm as $k=>$com){
				$komid[]	= $com["kom_id"];
				$comid[]	= $com["komentar_id"];
				$prep_id[]	= $com["preporuka_id"];
				$txt[]		= $com["komentar"];
				$titles[]	= $com["naslov"];
				$dates[]	= $com["datum"]>0?date($this->getFromConfig("short_date"),$com["datum"]):"";
				$signs[]	= $com["posiljalac"];
				$controls[]	= $com["kontrola"]==0?"nonactive":"";
				$controls1[]= $com["kontrola"];
				$mesta[]	= $com["grad"];
				$adrese[]	= $com["adresa"];
				$emails[]	= $com["email"];
				$tels[]	= $com["telefon"];
				
				if($k < (count($comm)-1)){
					$last[] = "";
				}else{
					$last[] = "last";
				}
			}
			$this->assign("comm_komitent_id",$komid);
			$this->assign("comm_control",$controls);
			$this->assign("comm_control1",$controls1);
			$this->assign("comm_id",$comid);
			$this->assign("prep_id",$prep_id);
			$this->assign("comm_naslov",$titles);
			$this->assign("comm",$txt);
			$this->assign("comm_datum",$dates);
			$this->assign("comm_sign",$signs);
			$this->assign("comm_mesto",$mesta);
			$this->assign("comm_adresa",$adrese);
			$this->assign("comm_email",$emails);
			$this->assign("comm_tel",$tels);
			
			$this->assign("comm_last",$last);
			
			$ret["txt"] = $this->parseTemplate("preporuke/komentari.tpl");
			$ret["count"] = count($comm);
		}
		
		return $ret;
	}
	
	function get_PreporukeTipovi($tipid=null){
		$q = "SELECT tip_id, tip_name FROM preporuke_tipovi ORDER BY tip_name";
		$res = $this->db->select2($q);
		if($res !== false){
			foreach ($res as $k=>$row){
				$ret["polje_id"][$k] = $row["tip_id"];
				$ret["polje_ime"][$k] = $row["tip_name"];
				if($row["tip_id"] == $tipid){
					$ret["polje_selected"][$k] = " selected";
				}else{
					$ret["polje_selected"][$k] = "";
				}
			}
			return $ret;
		}else{
			return false;
		}
	}
	function get_PreporukeTeme($temaid=null){
		$q = "SELECT tema_id, tema_name FROM preporuke_teme ORDER BY tema_name";
		$res = $this->db->select2($q);
		if($res !== false){
			foreach ($res as $k=>$row){
				$ret["polje_id"][$k] = $row["tema_id"];
				$ret["polje_ime"][$k] = $row["tema_name"];
				if($row["tema_id"] == $temaid){
					$ret["polje_selected"][$k] = " selected";
				}else{
					$ret["polje_selected"][$k] = "";
				}
			}
			return $ret;
		}else{
			return false;
		}
	}
	
	function getStyle(){
		$style_li = array(
			"pohvala"			=> "border-color:#449314; background-color:#d4e37e;",
			"primedba"			=> "border-color:#ca8738; background-color:#ffb155;",
			"sugestija"			=> "border-color:#c0b64f; background-color:#eee371;",
			"pitanje"			=> "border-color:#c29c27; background-color:#ecc344;",
			"poslovna ponuda"	=> "border-color:#8dbccc; background-color:#ccdbe5;"
		);
		$style_h1 = array(
			"pohvala"			=> "background-image:url(gui/icons/preporuke/pohvala_24.gif);",
			"primedba"			=> "background-image:url(gui/icons/preporuke/primedba_24.gif);",
			"sugestija"			=> "background-image:url(gui/icons/preporuke/sugestija_24.gif);",
			"pitanje"			=> "background-image:url(gui/icons/preporuke/pitanje_24.gif);",
			"poslovna ponuda"	=> "background-image:url(gui/icons/preporuke/poslovna_ponuda_24.gif);"
		);
		$style_date = array(
			"pohvala"			=> "color:#949e58;",
			"primedba"			=> "color:#b27c3b;",
			"sugestija"			=> "color:#a69e4f;",
			"pitanje"			=> "color:#a5882f;",
			"poslovna ponuda"	=> "color:#8e99a0;"
		);
		$style_sign = array(
			/*"pohvala"			=> "color:#7a8a1f;",
			"primedba"			=> "color:#d63914;",
			"sugestija"			=> "color:#aa9907;",
			"pitanje"			=> "color:#c68810;",
			"poslovna ponuda"	=> "color:#4688a7;"*/
		);
		$style_comm = array(
			"pohvala"			=> "border-top-color:#aab665; color:#aab665;",
			"primedba"			=> "border-top-color:#cc8e44; color:#cc8e44;",
			"sugestija"			=> "border-top-color:#beb65a; color:#beb65a;",
			"pitanje"			=> "border-top-color:#bd9c36; color:#bd9c36;",
			"poslovna ponuda"	=> "border-top-color:#a3afb7; color:#a3afb7;"
		);
		
		return array($style_li,$style_h1,$style_date,$style_sign,$style_comm);
	}
	function get_KomitentDelatnosti($komid){
		$ret = false;
		if($komid>0){
			$res = $this->db->select1("SELECT DISTINCT komdel_del_id FROM komitenti_delatnosti WHERE komdel_kom_id=$komid");
			if($res !== false){
				foreach ($res as $row){
					$ret[] = $row[0];
				}
			}
		}
		return $ret;
	}
}
?>